<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title>{$page_info.title}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body class="pear-container">
<div class="layui-padding-2">
    <div class="layui-card layui-panel">
        <div class="layui-padding-2">
            <div class="layui-form" >
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title">
                        {foreach $sys_type as $k2=>$v2}
                        <li {if ($k2 == 1)}class="layui-this"{/if}>{$v2}</li>
                        {/foreach}
                    </ul>
                    <div class="layui-tab-content">
                        {foreach $sys_type as $k=>$v}

                                <div class="layui-tab-item {if($k == 1)}layui-show{/if}">
                                    <div class="layui-padding-2">
                                        {foreach $sys_array as $k1=>$v1}
                                        {if($k === $k1)}
                                        {foreach $sys_array[$k1] as $value}
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">{$value.name}</label>
                                            <div class="layui-input-block layui-input-wrap">
                                                {if(in_array($value.form_type,['text','number','password']))}
                                                <input type="{$value.form_type}" name="{$value.s_key}" value="{$value.content}" placeholder="" autocomplete="off" class="layui-input">
                                                {elseif($value.form_type === 'textarea')/}
                                                <textarea placeholder="{$value.description}" name="{$value.s_key}" class="layui-textarea">{$value.content}</textarea>
                                                {elseif(in_array($value.form_type,['radio','checkbox','select']) && !empty($value.input_v))/}
                                                    {if($value.form_type === 'radio')}
                                                        {foreach $value.input_v as $radio}
                                                        <input type="{$value.form_type}" name="{$value.s_key}" value="{$radio[0]}" title="{$radio[1]}" {if($value.content === $radio.0)}checked{/if}>
                                                        {/foreach}
                                                    {elseif($value.form_type === 'select')/}
                                                    <select name="{$value.s_key}">
                                                        {foreach $value.input_v as $select}
                                                        <option value="{$select[0]}">{$select[1]}</option>
                                                        {/foreach}
                                                    </select>
                                                    {elseif($value.form_type === 'checkbox')/}
                                                        {foreach $value.input_v as $ckey=>$checkbox}
                                                        <input type="{$value.form_type}" name="{$value.s_key}[{$ckey}]" value="{$checkbox[0]}" lay-skin="tag" title="{$checkbox[1]}" {if(in_array($checkbox.0,$value.content))}checked{/if}>
                                                        {/foreach}
                                                    {/if}
                                                {elseif($value.form_type === 'file_img')/}
                                                <input type="hidden" name="{$value.s_key}" value="{$value.content}" id="up_{$value.s_key}">
                                                <div class="layui-upload-drag" style="display: block;" onclick="mor_file_upload('{$value.s_key}','image')">
                                                    <i class="layui-icon layui-icon-upload"></i>
                                                    <div>点击上传，或将图片拖拽到此处</div>
                                                    <div class="{if(empty($value.content))}layui-hide{/if}" id="img_p_{$value.s_key}">
                                                        <hr> <img src="{$value.content}" alt="" style="max-width: 100%;height: 100px;width: 300px">
                                                    </div>
                                                </div>
                                                {elseif($value.form_type === 'file')}
                                                <input type="text" name="{$value.s_key}" class="layui-input" value="{$value.content}" id="up_{$value.s_key}">
                                                <button type="button" class="layui-btn" onclick="mor_file_upload('{$value.s_key}','file')">
                                                    <i class="layui-icon layui-icon-upload"></i> 文件上传
                                                </button>
                                                {elseif($value.form_type === 'date_time')/}
                                                <input type="text" name="{$value.s_key}" class="layui-input {$table_id}_date_time" placeholder="yyyy-MM-dd HH:mm:ss" value="{$value.content ?? ''}">
                                                {elseif($value.form_type === 'editor')}
                                                <textarea name="{$value.s_key}" id="{$table_id}-editor-{$value.s_key}" class="layui-textarea">{$value.content ?? ''}</textarea>
                                                {/if}
                                                <div class="layui-form-mid layui-text-em" style="float: none;">{$value.description}</div>
                                            </div>
                                        </div>
                                        {/foreach}
                                        {/if}
                                        {/foreach}
                                    </div>
                                </div>
                        {/foreach}
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn sys_submit" lay-submit lay-filter="sys_submit">立即提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__ADMINS__tinymce/tinymce.min.js"></script>
<script>
    {foreach $sys_array as $k2=>$v2}
        {foreach $sys_array[$k2] as $values}
            {if($values.form_type === 'editor')}
            tinymce.init({
                selector: 'textarea#{$table_id}-editor-{$values.s_key}',
                plugins: 'image',
                language:'zh_CN',
                images_upload_url: '{:url("admin/index/upload")}'
            });
            {/if}
        {/foreach}
    {/foreach}
</script>
<script>

    layui.use(['form','toast', 'popup'], function() {
        var $ = layui.$;
        var form = layui.form;
        var toast = layui.toast;
        var popup = layui.popup;
        var laydate = layui.laydate;


        form.on('submit(sys_submit)', function(data){
            var field = data.field; // 获取表单字段值
            {foreach $sys_array as $k2=>$v2}
            {foreach $sys_array[$k2] as $values}
            {if($values.form_type === 'editor')}
            field['{$values.s_key}'] = tinymce.get('{$table_id}-editor-{$values.s_key}').getContent();
            {/if}
                {/foreach}
                    {/foreach}


            $.post('{:url("admin/system/update")}',field,function(res){
                if(res.code === 200){
                    popup.success(res.msg, function () {
                        PearAdmin.refresh();
                    });
                }else{
                    toast.error({
                        message: res.msg,
                    });
                }
            })
            return false;
        });
        laydate.render({
            elem: '.{$table_id}_date_time',
            type: 'datetime'
        });
        form.render();
    })

</script>
</body>
</html>